import ajax from './ajax'
import '../css/reg.css'

let form = document.forms[0]
form.onsubmit = function (e) {
    e.preventDefault();
    if (form.username.value !== '' && form.password.value !== '') {
        ajax('post', '/api/reg', { username: form.username.value, password: form.password.value }).then(function (result) {

            if (result.flag) {
                alert('注册成功')
                location.assign("login.html")
            } else {
                alert('用户名已存在')
            }
        })
    } else {
        alert('用户名密码不能为空')
    }

}